//
//  UIViewController+ZLExtension.m
//  ZLAlert-OC
//
//  Created by 科大 on 2024/1/2.
//

#import "ZLExtension+Extension.h"

@implementation UIViewController (Extension)
+ (UIViewController *)zl_topViewController:(nullable UIViewController *)controller {
    if ([controller isKindOfClass:[UINavigationController class]]) {
        UINavigationController *navigationController = (UINavigationController *)controller;
        return [self zl_topViewController:navigationController.visibleViewController];
    }
    
    if ([controller isKindOfClass:[UITabBarController class]]) {
        UITabBarController *tabController = (UITabBarController *)controller;
        return [self zl_topViewController:tabController.selectedViewController];
    }
    
    if (controller.presentedViewController) {
        return [self zl_topViewController:controller.presentedViewController];
    }
    
    return [UIApplication sharedApplication].keyWindow.rootViewController;
}

@end

@implementation UILabel (Extension)
+ (UILabel *)zl_labelWithConfig:(ZLAlertItemConfig *)config {
    UILabel *label = [[UILabel alloc] init];
    label.font = config.font;
    label.textColor = config.color;
    label.textAlignment = config.alignment;
    label.backgroundColor = config.backgroundColor;
    label.layer.cornerRadius = config.cornerRadius;
    label.layer.borderWidth = config.borderWidth;
    label.layer.borderColor = config.borderColor.CGColor;
    label.layer.masksToBounds = YES;
    return label;
}

@end
